﻿using UnityEngine;
using System.Collections;

public class RotateLookTarget : MonoBehaviour {

	public float rotationSpeed;

	public void RotateToTarget(Transform target){
		if (target == null) return;
		Vector3 dir = target.position - transform.position;
		dir.y = 0;
		dir.Normalize ();

		Quaternion from = transform.rotation;
		Quaternion to = Quaternion.LookRotation (dir);
		transform.rotation = Quaternion.Lerp(from,to,rotationSpeed * Time.deltaTime);
	}

}